//
//  YDExpectedReferenceView.m
//  PeiZiWangBei
//
//  Created by LK-IOS on 2018/3/2.
//  Copyright © 2018年 LK-IOS. All rights reserved.
//

#import "YDExpectedReferenceView.h"
#import "YDExpectedReferenceCell.h"
#import "YDExpectedReferenceModel.h"


@interface YDExpectedReferenceView()<UITableViewDelegate , UITableViewDataSource>

@property (nonatomic , assign) CGFloat cellH;
@property (nonatomic , weak) UITableView *tableView;


@end

@implementation YDExpectedReferenceView

-(void)setModelArray:(NSMutableArray *)modelArray
{
    _modelArray = modelArray;
    
    [self.tableView reloadData];
    
    
}
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.layer.masksToBounds = YES;
        self.layer.borderWidth = 1.f;
        self.layer.borderColor = [UIColor colorWithHexString:blueyGrey].CGColor;
        self.backgroundColor = [UIColor whiteColor];
        _cellH = (isPhoneX ? rateX812(135) : rate750(135)) * 0.2;
        [self tableView];
        
    }
    return self;
}

+(instancetype)initExpectedReferenceViewWithReferenceDataArray:(NSMutableArray *)modelArray
{
    YDExpectedReferenceView *referenceView = [[self alloc] init];
    
    referenceView.modelArray = modelArray;
    
    return referenceView;
}
/*******tableView********/
-(UITableView *)tableView
{
    if (_tableView == nil) {
        UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        [self addSubview:tableView];
        tableView.backgroundColor = [UIColor whiteColor];
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        tableView.dataSource = self;
        tableView.delegate = self;
        tableView.estimatedRowHeight = 0;
        tableView.estimatedSectionFooterHeight = 0;
        tableView.estimatedSectionHeaderHeight = 0;
        if (isIos11) {
            tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
        [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.bottom.equalTo(self);
        }];
        tableView.scrollEnabled = NO;
        _tableView = tableView;
    }
    return _tableView;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.modelArray.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return _cellH;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    YDExpectedReferenceCell *cell = [YDExpectedReferenceCell cellWithTableView:tableView];
    if (indexPath.row == 0) {
        cell.labelL.textColor = [UIColor colorWithHexString:dark];
        cell.labelM.textColor = [UIColor colorWithHexString:dark];
        cell.labelR.textColor = [UIColor colorWithHexString:dark];
    }else{
        cell.labelL.textColor = [UIColor colorWithHexString:paleRed];
        cell.labelM.textColor = [UIColor colorWithHexString:paleRed];
        cell.labelR.textColor = [UIColor colorWithHexString:paleRed];
    }
    YDExpectedReferenceModel *model = self.modelArray[indexPath.row];
    cell.model = model;
    return cell;
}


@end
